package com.eystar.ext.plugin.crate;

import com.eystar.ext.plugin.crate.db.CrateDb;
import com.eystar.ext.plugin.crate.db.CratePool;
import com.jfinal.log.Log;
import com.jfinal.plugin.IPlugin;

public class CratePlugin implements IPlugin {
	protected final Log logger = Log.getLog(getClass());
	private String crateCluster;
	private boolean showSql;
	
	public CratePlugin(String crateCluster){
		this.crateCluster = crateCluster;
		this.showSql = false;
	}
	public CratePlugin(String crateCluster, boolean showSql){
		this.crateCluster = crateCluster;
		this.showSql = showSql;
	}

	@Override
	public boolean start() {
		CrateDb.init("io.crate.client.jdbc.CrateDriver",crateCluster,showSql);
		logger.info("CratePlugin 加载完成......");
		return true;
	}

	@Override
	public boolean stop() {
		if (CratePool.getPool() != null) {
			CratePool.getPool().close();
		}
		return true;
	}

	public void setShowSql(boolean showSql) {
		this.showSql = showSql;
	}

}
